<template>
	<view class="box">
		<u-popup v-model="show" mode="bottom" width="90%" height="600" borderRadius="54">
			<view class="d_f j_c_c a_i_c f_d_c">
				<view class="title">
					请输入购买手机号进行登录
				</view>

				<view style="margin-top: 50rpx;">
					<u-field v-model="mobile" label="手机号" placeholder="请填写手机号" maxlength="11" type="number">
					</u-field>
					<u-field v-model="code" label="验证码" placeholder="请填写验证码" type="number" maxlength="6">
						<u-button size="mini" slot="right" type="primary" @click="getCode" shape="circle"
							:disabled="disabled">{{getCodeText}}
						</u-button>
					</u-field>
				</view>
				<image src="https://web.78keji.cn/newimgaes/loginxs.png" mode="widthFix"
					style="600rpx;margin-top: 40rpx;" @click="login">
				</image>
			</view>


		</u-popup>
		<u-popup v-model="shuoming" mode="center" width="90%" height="600" borderRadius="54">
			<view class="d_f j_c_c a_i_c f_d_c">

				<image src="https://web.78keji.cn/newimgaes/shuoming.png" mode="widthFix"
					style="600rpx;margin-top: 40rpx;position: relative;">
				</image>

			</view>
			<image src="https://web.78keji.cn/newimgaes/quxiao.png" mode="widthFix"
				style="position: absolute;width: 50rpx;right:88rpx;top: 30px;" @click="shuoming=false"></image>


		</u-popup>
		<u-popup v-model="showx" mode="center" width="90%" :mask-close-able='false'>

			<image src="https://web.78keji.cn/newimgaes/zfb.png" mode="widthFix"
				style="width: 100%;position: relative;"></image>

			<view class="" style="width: 100%;position: absolute;top: 30rpx;">
				<view class="d_f j_c_c" style="color: #2A63D9;font-size: 36rpx;">
					确认到账支付宝账号
				</view>
				<view class="d_f j_c_c" style="width: 100%;margin-top: 48rpx;">
					<view class="d_f a_i_c "
						style="border: 1px solid #B3B3B3;width: 560rpx;height: 80rpx;border-radius: 40rpx;padding: 0 23rpx;">
						<image src="https://web.78keji.cn/newimgaes/icon.png" mode="widthFix" style="width: 43rpx;">
						</image>
						<view class="" style="width: 1rpx;
height: 40rpx;border-right: 1px solid #999999;margin-left: 12rpx;">

						</view>
						<input type="number" placeholder="请输入领取支付宝账号" style="margin-left: 12rpx;" v-model="content">
					</view>

				</view>
				<view class="d_f j_c_c">
					<image src="https://web.78keji.cn/newimgaes/newlq.png" mode="widthFix"
						style="width:536rpx;margin-top: 30rpx;" @click="viplingqu"></image>
				</view>

			</view>
			<view class="d_f j_c_c">
				<image src="https://web.78keji.cn/newimgaes/quxiao.png" mode="widthFix" style="width: 68rpx;"
					@click="showx=false"></image>
			</view>


		</u-popup>
		<u-popup v-model="showr" mode="center" width="90%" :mask-close-able='false'>

			<image src="https://web.78keji.cn/newimgaes/results.png" mode="widthFix"
				style="width: 100%;position: relative;"></image>
			<image src="https://web.78keji.cn/newimgaes/closex.png" mode="widthFix"
				style="width: 50rpx;position: absolute;top: 30rpx;z-index: 88;right: 10rpx;" @click="showr=false">
			</image>
			<view class="" style="width: 100%;position: absolute;top: 30rpx;">

				<view class="d_f j_c_c">
					<image src="https://web.78keji.cn/newimgaes/ck.png" mode="widthFix"
						style="width:397rpx;margin-top: 370rpx;" @click="kabao"></image>
				</view>

			</view>


		</u-popup>
		<view class="" style="position: fixed;right: 0;left: 0;z-index: 1;top: 0;">
			<image src="https://web.78keji.cn/newimgaes/loginys.png" mode="widthFix" style="width: 100%;" v-if="openid">
			</image>

			<image src="https://web.78keji.cn/newimgaes/bgx.png" mode="widthFix" style="width: 100%;" v-else></image>
			<!-- 	<view class="d_f a_i_c"
				style="position: absolute;right: 50rpx;margin-top: -70rpx;font-size: 26rpx;color: #1B86FF;"
				@click="shuoming=true">
				<image src="https://web.78keji.cn/newimgaes/icons.png" mode="widthFix"
					style="width: 100%;width: 60rpx;"></image>
				领取说明
			</view> -->
			<view class="" v-for="(item,index) in listxs">

			</view>


			<view class="d_f a_i_c" style="position: absolute;top: 28rpx;left:205rpx ;">

				<view class="" style="margin-left: 56rpx;" v-if="openid">
					<view class="" style="color: white;font-size: 36rpx;">
						{{mobile}}
					</view>

				</view>

				<view class="d_f a_i_c" v-else style="margin-left: 70rpx;">
					<!-- <view class="" style="color: white;font-size: 32rpx;background-color: blueviolet;padding: 10rpx;border-radius: 20rpx;" >
						一键登录
					</view> -->

				</view>
				<image src="https://web.78keji.cn/newimgaes/loginout.png" mode="widthFix"
					style="width: 120rpx;margin-left: 94rpx;" @click="loginout" v-if="openid">



			</view>

		</view>

		<view class="" v-if="openid" style="padding-top: 202rpx;">



			<view class="">
				<view class="" v-if="!openid||tldata.length==0">
					<view class="d_f j_c_c">
						<image src="https://web.78keji.cn/newimgaes/no.png" mode="widthFix"
							style="width: 273rpx;margin-top: 143rpx;">
						</image>

					</view>
					<view class="d_f j_c_c" style="color: #808080;font-size: 24rpx;">
						暂无立减金
					</view>
				</view>

				<view class="" v-else>

					<view class="" style="margin-top: 48rpx;">

						<view v-for="(item,index) in tldata" :key="index"
							:class="index==tldata.length-1?'boss1':'boss'">

							<view class="" v-if="item.status==0||item.status==7"
								style="padding-bottom: 10rpx;background-color: #FAFAFA;">

								<image src="https://web.78keji.cn/newimgaes/back5.png" mode="widthFix"
									style="width: 100%;"></image>

								<view class="d_f" style="position: absolute;top: 0rpx;left: 30rpx;">
									<view class="d_f " style="color: #FFFFFF;font-weight: 800;">
										<view class="money">
											{{item.money}}
										</view>
										<view class="unit">
											元
										</view>



									</view>
									<view class="" style="margin-left: 70rpx;margin-top: 30rpx;">
										<view class="" style="text-align: left;color: #232323;font-weight: bold;">
											通用立减金
										</view>
										<view class=""
											style="text-align: left;font-size: 16rpx;color: #0F0F0F;margin-top: 33rpx;">
											有效期{{item.starttime}}-{{item.endtime}}
										</view>
									</view>
									<view class="d_f j_c_c a_i_c" style="margin-left: 64rpx;">
										<view class=""
											style="color: #E8593F;font-size: 24rpx;width: 136rpx;margin-top: 20rpx;"
											v-if="item.status==0">
											<view class="text-button" @click="changex(item)" v-if="item.check==false">
												优惠券领取</view>
											<get-coupon v-else onBeforeGetCoupon="onBeforeGetCoupon"
												onGetCouponSuccess="onGetCouponSuccess"
												onGetCouponFail="onGetCouponFail" onUseImmediately="onUseImmediately"
												onClose="onClose" senderMerchantId='2088641608058156' :params="zfbPrams"
												:zIndex="9998" :extraData="'Any Data'">
												<view class="text-button">确定领取</view>
											</get-coupon>

										</view>


										<image src="https://web.78keji.cn/newimgaes/timeno.png" mode="widthFix"
											style="width: 136rpx;margin-top: 33rpx;" v-if="item.status==7"></image>

									</view>
								</view>
							</view>
							<view class=""
								v-if="item.status==2||item.status==1||item.status==3||item.status==4||item.status==5||item.status==6"
								style="padding-bottom: 10rpx;background-color: #FAFAFA;">
								<image src="https://web.78keji.cn/newimgaes/yilingqu.png" mode="widthFix"
									style="width: 100%;" v-if="item.status==1"></image>
								<image src="https://web.78keji.cn/newimgaes/err.png" mode="widthFix"
									style="width: 100%;" v-else></image>

								<view class="d_f" style="position: absolute;top: 0rpx;left: 30rpx;">
									<view class="d_f " style="color: #9A9A9A;font-weight: 800;">
										<view class="money">
											{{item.money}}
										</view>
										<view class="unit">
											元
										</view>

									</view>
									<view class="" style="margin-left: 70rpx;margin-top: 30rpx;">
										<view class="" style="text-align: left;color: #9A9A9A;font-weight: bold;">
											通用立减金
										</view>
										<view class=""
											style="text-align: left;font-size: 16rpx;color: #9A9A9A;margin-top: 33rpx;">
											有效期{{item.starttime}}-{{item.endtime}}
										</view>
									</view>
									<view class="d_f j_c_c a_i_c" style="margin-left: 64rpx;">

										<view class="" style="color: #5EBB72;font-size: 24rpx;width: 136rpx;"
											v-if="item.status==1">
											<image src="https://web.78keji.cn/newimgaes/chakan.png" mode="widthFix"
												style="width: 100%;margin-top: 60rpx;" @click="kabao"></image>
										</view>
										<view class="" style="color: #5EBB72;font-size: 24rpx;width: 136rpx;"
											v-if="item.status==3">
											发券成功
										</view>
										<view class=""
											style="color: #E8593F;font-size: 24rpx;width: 136rpx;margin-top: 20rpx;"
											v-if="item.status==2">
											发券失败
											<view class=""
												style="font-size: 24rpx;width: 136rpx;margin-top: 20rpx;background-color: #1E7AFF;height: 46rpx;line-height: 46rpx;border-radius: 23rpx;color: white;">



												<view class="text-button" @click="changex(item)"
													v-if="item.check==false" style="margin-top: 30rpx;">优惠券领取</view>
												<get-coupon v-else onBeforeGetCoupon="onBeforeGetCoupon"
													onGetCouponSuccess="onGetCouponSuccess"
													onGetCouponFail="onGetCouponFail"
													onUseImmediately="onUseImmediately" onClose="onClose"
													:params="zfbPrams" :zIndex="9998" :extraData="'Any Data'">
													<view class="text-button">确定领取</view>
												</get-coupon>
											</view>
										</view>
										<view class=""
											style="color: #E8593F;font-size: 24rpx;width: 136rpx;margin-top: 20rpx;"
											v-if="item.status==5">
											领取失败
											<view class=""
												style="font-size: 24rpx;width: 136rpx;margin-top: 20rpx;background-color: #1E7AFF;height: 46rpx;line-height: 46rpx;border-radius: 23rpx;color: white;">

												<view class="text-button" @click="changex(item)"
													v-if="item.check==false" style="margin-top: 30rpx;">加油领取</view>
												<get-coupon v-else onBeforeGetCoupon="onBeforeGetCoupon"
													onGetCouponSuccess="onGetCouponSuccess"
													onGetCouponFail="onGetCouponFail"
													onUseImmediately="onUseImmediately" onClose="onClose"
													:params="zfbPrams" :zIndex="9998" :extraData="'Any Data'">
													<view class="text-button">确定领取</view>
												</get-coupon>
											</view>
										</view>
										<view class=""
											style="color: #999999;font-size: 24rpx;text-align: center;width: 136rpx"
											v-if="item.status==4">
											已核销
										</view>
										<view class=""
											style="color: #999999;font-size: 24rpx;text-align: center;width: 136rpx"
											v-if="item.status==6">
											已到期
										</view>


									</view>
								</view>
							</view>

						</view>
					</view>
				</view>
				<view class="" style="height: 266rpx;">

				</view>


			</view>
		</view>
		<view class="" v-else style="width: 100%;text-align: center;padding-top: 390rpx;position: relative;">
			<image src="https://web.78keji.cn/newimgaes/nologins.png" mode="widthFix" style="width:543rpx;"></image>
			<view class="" style="color: #808080;font-size: 24rpx;margin-top: 20rpx;">
				请登录查看
			</view>

			<image src="../../static/yijian.png" mode="widthFix" style="width: 397rpx;margin-top: 71rpx;"></image>
			<view class="d_f j_c_c">
				<button class="login" type="default" open-type="getAuthorize" @getAuthorize="onGetAuthorize"
					scope='phoneNumber'
					style="position: absolute;width: 397rpx;height: 96rpx;margin-top: -126rpx;opacity: 0;"></button>
			</view>
		</view>




	</view>
</template>

<script>
	import {
		sendSms,
		checkSms,
		ljjList,
		wxLogins,
		ljjLq,
		getProType,
		openSignDecrypt,
		ljjStatusEdit,
		jyqList,
		jyqStatusEdit
	} from '../../api/index.js'
	import moment from '../../utils/moment.js'
	import md5 from '../../utils/md5.js'
	export default {
		data() {
			return {
				listxs: [{
						id: 13,
						check: false
					},
					{
						id: 14,
						check: false
					},
					{
						id: 15,
						check: false
					},
				],
				zfbPrams: [],
				shuoming: false,
				content: '',
				border: true,
				showx: false,
				showr: false,
				listx: [

					{
						name: '工商银行微信立减金',
						id: '1931'
					},
					{
						name: '招商银行微信立减金',
						id: '3008'
					},
					{
						name: '农业银行微信立减金',
						id: '3009'
					},
					{
						name: '建设银行微信立减金',
						id: '3010'
					},
					{
						name: '中国银行微信立减金',
						id: '3011'
					},

				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: '',
				shows: false,
				list: [{
					name: '优酷视频'
				}, ],
				current: 0,
				mobile: "",
				show: false,
				code: "",
				getCodeText: '获取验证码',
				getCodeBtnColor: "#ffffff",
				getCodeisWaiting: false,
				disabled: false,
				openid: "", //是否登录
				proType: '',
				xmlydata: [],
				tldata: [],
				ljjid: "", //立减金id
				idx: "", //省心会员券id
				flag: 0,
				idss: ""


			}
		},
		components: {

		},
		methods: {

			changex(item) {
				console.log(item)
				for (var i in this.tldata) {
					if (item.id == this.tldata[i].id) {
						this.tldata[i].check = true
						this.idss = this.tldata[i].id
					} else {
						this.tldata[i].check = false
					}
				}
				if(item.ac_id!=''){
					this.zfbPrams = [{
						activityId:item.ac_id,
					
						//测试：2024051600826004152129477292
						//正式：2024051600826004152129477292
						outBizNo: this.idss,
					
						voucherCode: this.idss, //非导码模式商家券
					}]
				}else{
					this.zfbPrams = [{
						activityId: '2024070800826004155831076954',
					
						//测试：2024051600826004152129477292
						//正式：2024051600826004152129477292
						outBizNo: this.idss,
					
						voucherCode: this.idss, //非导码模式商家券
					}]
				}
		
			},
			fa(item) {





			},
			addss(item) {
				uni.setStorageSync('nid', item)
			},
			getdata() {
				jyqList({
					openid: this.openid,
					type: 3,
					proType: 4
				}).then((res) => {
					this.tldata = res.data
					this.tldata.forEach((item, index) => {
						Object.assign(item, {
							check: false
						})
					})
					for (var i in this.tldata) {
						if (this.tldata[i].status == 0) {
							if (Date.now() < this.tldata[i].starttime * 1000) {
								this.tldata[i].status = '7'
							}
						}
						// this.tldata[i].status = '0'

						this.tldata[i].starttime = moment(this.tldata[i].starttime * 1000).format(
							"YYYY-MM-DD")
						this.tldata[i].endtime = moment(this.tldata[i].endtime * 1000).format("YYYY-MM-DD")
					}
					console.log(this.tldata)

				})
			},
			kabao() {
				let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
					"alipayqr://platformapi/startapp?saId=88888888")

				my.ap.navigateToAlipayPage({
					path: link
				})


			},
			onGetAuthorize() {
				uni.showLoading({
					title: "授权中",
					mask: true
				})
				my.getPhoneNumber({
					success: (res) => {
						let encryptedData = res.response;
						console.log(encryptedData)
						openSignDecrypt({
							encryptedData: JSON.parse(encryptedData).response,

						}).then((resx) => {
							console.log(resx)
							uni.hideLoading()

							uni.setStorageSync('mobile', resx.data.mobile)
							uni.setStorageSync('openid', resx.data.openid)
							this.mobile = resx.data.mobile
							this.openid = resx.data.openid
							this.getdata()

						})

					},
					fail: (res) => {
						console.log(res);
						uni.hideLoading()
						console.log('getPhoneNumber_fail');
					},
				});


			},
			add(item) {
				this.shows = true
				this.ljjid = item
			},
			viplq(item) {
				console.log()

				this.idx = item.id

				console.log(item)

				this.showx = true



			},
			//支付宝领取
			viplingqu() {
				uni.showLoading({
					title: '领取中，请稍等',
					mask: true
				});
				ljjLq({
					openid: this.openid,
					type: 3,
					id: this.idx,
					account: this.content,
					accountType: 1,
					bankType: 2

				}).then((res) => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					}); //弹出提示框
					this.showx = false
					this.showr = true
					this.getdata()
				}).catch((err) => {
					console.log(err)
					uni.showToast({
						title: err.data.msg,
						icon: "none"
					});
				})
			},
			lingqus() {
				if (this.value == '') {

					uni.showToast({
						title: '请先选择发放立减金银行',
						icon: "error"
					}); //弹出提示框
				} else {
					uni.showLoading({
						title: '领取中，请稍等',
						mask: true
					});
					ljjLq({
						openid: this.openid,
						type: 3,
						id: this.ljjid,
						account: uni.getStorageSync('openidHF'),
						accountType: 2,
						bankType: this.value

					}).then((res) => {
						uni.showToast({
							title: res.msg,
							icon: "none"
						}); //弹出提示框
						this.shows = false
						this.getdata()
					})
				}

			},

			//推出登录
			loginout() {

				this.openid = ''
				this.xmlydata = []
				this.tldata == []
				uni.clearStorageSync()
			},

			onGetCouponSuccess(resultList) {

				console.log('触发了 onGetCouponSuccess 事件')
				console.log('成功返回结果: ', resultList)
				if (resultList[0].code == 'SUCCESS') {
					jyqStatusEdit({
						openid: uni.getStorageSync('openid'),
						type: 3,
						id: this.idss,
						voucherId: resultList[0].voucherId
					}).then((res) => {
						this.getdata()
					})
				} else if (resultList[0].code == 'ACTIVITY_NOT_START') {
					uni.showToast({
						title: '活动未开始',
						icon: 'none', //将值设置为 success 或者 ''
						duration: 2000 //持续时间为 2秒
					})
				} else if (resultList[0].code == 'COUNT_OVER_LIMIT') {
					uni.showToast({
						title: '领取次数超过限制',
						icon: 'none', //将值设置为 success 或者 ''
						duration: 2000 //持续时间为 2秒
					})
				} else if (resultList[0].code == 'BUDGET_NOT_ENOUGH') {
					uni.showToast({
						title: '预算不足',
						icon: 'none', //将值设置为 success 或者 ''
						duration: 2000 //持续时间为 2秒
					})
				} else if (resultList[0].code == 'OTHER') {
					uni.showToast({
						title: '其他原因，请联系客服',
						icon: 'none', //将值设置为 success 或者 ''
						duration: 2000 //持续时间为 2秒
					})
				}

			},
			onGetCouponFail(result) {
				console.log('触发了 onGetCouponFail 事件')
				console.log('失败返回结果: ', result)
				uni.showToast({
					title: result.errorMsg,
					icon: 'none', //将值设置为 success 或者 ''
					duration: 2000 //持续时间为 2秒
				})
			},

			onClose(event) {
				console.log('触发了 onClose 事件')
			},
		},
		onLoad(option) {
			console.log(7777)
			this.$scope.onClose = this.onClose.bind(this)
			this.$scope.onGetCouponSuccess = this.onGetCouponSuccess.bind(this)
			this.$scope.onGetCouponFail = this.onGetCouponFail.bind(this)

			if (option.openid) {
				uni.setStorageSync('openid', option.openid)
			}
			if (option.mobile) {
				uni.setStorageSync('mobile', option.mobile)
				this.openid = md5.hex_md5(option.mobile + '456')
				uni.setStorageSync('openid', this.openid)
			}
			if (option.openidHF) {
				uni.setStorageSync('openidHF', option.openidHF)
			}
			if (uni.getStorageSync('openid')) {
				console.log(11111)
				this.openid = uni.getStorageSync('openid')
				this.getdata()

			}
			if (uni.getStorageSync('mobile')) {
				this.mobile = uni.getStorageSync('mobile')

			}


		},
		watch: {

		},
		computed: {

		}
	}
</script>

<style scoped lang='scss'>
	.cx {
		width: 136rpx;
		height: 50rpx;
		background: linear-gradient(90deg, #5B8CCF, #6570CB);
		border: 2px solid #FFFFFF;
		border-radius: 25rpx;
		line-height: 50rpx;
		color: #FFFFFF;
		margin-top: 15rpx;
	}

	.money {
		font-size: 90rpx;
		color: white;
		margin-top: 16rpx;
		margin-left: 10rpx;
	}

	.unit {
		margin-top: 76rpx;
		color: white;
		font-size: 28rpx;
	}

	.box {
		background-color: #FFFFFF;
		min-height: 100vh;
	}

	.title {

		font-size: 34rpx;

		font-weight: 400;
		color: #1A1A1A;
		margin-top: 50rpx;

	}

	.boss1 {
		background-color: white;
		width: 662rpx;
		border-radius: 12rpx;
		margin: 0 auto;

		text-align: center;
		position: relative;
	}

	.boss {
		background-color: white;
		width: 662rpx;

		margin: 0 auto;

		text-align: center;
		position: relative;


	}

	.text-button {
		background-color: #5B8CCF;
		color: white;
		width: 140rpx;
		line-height: 52rpx;
		height: 52rpx;

		border-radius: 25rpx;
	}
</style>